//
//  EGAdViewCell.m
//  Orchard
//
//  Created by 黄勇锋 on 16/8/21.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "EGAdViewCell.h"
#import "EGAdView.h"

@interface EGAdViewCell()

@property (strong,nonatomic) EGAdView *adView;

@end



@implementation EGAdViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        //初始化属性
        self.backgroundColor = RANDOMCOLOR;
        
        [self setupUI];
    }
    
    return self;
}

- (void)setDataArray:(NSArray<EGHomeModel *> *)dataArray{
    
    _dataArray = dataArray;
    
    //给属性赋值
    for (int i = 0; i< dataArray.count; i++) {
        
        EGHomeModel *model = dataArray[i];
        
        [self.adView.imageViewArray[i] sd_setImageWithURL:[NSURL URLWithString:model.img]];
        
        self.adView.labelArray[i].text = model.name;
    }
}
    

- (void)setupUI{
    
    //添加控件
    [self.contentView addSubview:self.adView];
    //设置约束
    [self.adView makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(UIEdgeInsetsZero);
    }];
}

- (EGAdView *)adView{
    
    if (_adView == nil) {
        _adView = [[EGAdView alloc]init];
    }
    return _adView;
}


@end
